﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class AdminLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Request.Cookies["account"] != null)
        //{
        //    txtUserName.Text = Request.Cookies["account"].Values["user"].ToString();
        //}
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string user = txtUserName.Text;
        string pass = txtPassword.Text;
        try
        {
            if (user == "" || pass == "")
            {
                lblMessager.Text = "Bạn chưa điền đầy đủ thông tin";
                return;
            }
            else
            {
                SqlConnection con = new SqlConnection("server=KIENNT-PC\\SQLEXPRESS;database=OnlineMobileRecharge;uid=sa;pwd=123456");
                con.Open();
                SqlCommand cmd = new SqlCommand("select _password from AdminAccount where _username='" + user + "'", con);
                SqlDataReader sdr = cmd.ExecuteReader();
                sdr.Read();
                if (pass == sdr.GetValue(0).ToString())
                {
                    //if (cb1.Checked)
                    //{
                    //    HttpCookie cookie = new HttpCookie("account");
                    //    cookie.Values["user"] = user;
                    //    cookie.Values["pass"] = pass;
                    //    Response.Cookies.Add(cookie);
                    //}
                    //Session["login"] = user;
                    Response.Redirect("HomeAdmin.aspx");
                    sdr.Close();
                    con.Close();
                }
                else
                {
                    lblMessager.Text = ("Sai mật khẩu");
                }
                sdr.Close();
                con.Close();
            }
        }
        catch (Exception)
        {
            lblMessager.Text=("Tên đăng nhập và mật khẩu không hợp lệ...");
        }
    }
}